package com.housekeeping.housekeeping.administrator.adminsclassify.controller;

import com.housekeeping.housekeeping.administrator.adminsclassify.service.ClassifyService;
import com.housekeeping.housekeeping.administrator.adminsclassify.service.impl.ClassifyServiceImpl;
import com.housekeeping.housekeeping.administrator.entity.AdminsClassify;
import com.housekeeping.housekeeping.administrator.utils.Page;
import com.housekeeping.housekeeping.administrator.utils.ResponseEntity;
import com.housekeeping.housekeeping.administrator.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
@WebServlet("/classify/query")
public class QueryController extends HttpServlet {
    private ClassifyService service=new ClassifyServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        int page = Integer.parseInt(req.getParameter("page"));
        int size = Integer.parseInt(req.getParameter("size"));
        ResponseEntity<Page<AdminsClassify>> entity=null;
        try {
            Page<AdminsClassify> list = service.list(page, size);
             entity= ResponseEntity.success(list);
        } catch (SQLException throwables) {
            entity=ResponseEntity.error(400,"系统繁忙");
        }
        ResponseUtils.responseJson(resp,entity);
    }
}
